
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.analysis.defects.core &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../../" src="../../../../_static/documentation_options.js"></script>
    <script src="../../../../_static/jquery.js"></script>
    <script src="../../../../_static/underscore.js"></script>
    <script src="../../../../_static/doctools.js"></script>
    <script src="../../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.defects.core</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.analysis.defects.core</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Base classes representing defects.</span>
<span class="sd">&quot;&quot;&quot;</span>


<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>

<span class="kn">from</span> <span class="nn">abc</span> <span class="kn">import</span> <span class="n">ABCMeta</span><span class="p">,</span> <span class="n">abstractmethod</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">MSONable</span><span class="p">,</span> <span class="n">MontyDecoder</span>
<span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">lru_cache</span>

<span class="kn">from</span> <span class="nn">pymatgen.core.structure</span> <span class="kn">import</span> <span class="n">Structure</span><span class="p">,</span> <span class="n">PeriodicSite</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.composition</span> <span class="kn">import</span> <span class="n">Composition</span>
<span class="kn">from</span> <span class="nn">pymatgen.symmetry.analyzer</span> <span class="kn">import</span> <span class="n">SpacegroupAnalyzer</span>
<span class="kn">from</span> <span class="nn">pymatgen.analysis.defects.utils</span> <span class="kn">import</span> <span class="n">kb</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Danny Broberg, Shyam Dwaraknath&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2018, The Materials Project&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;1.0&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;Shyam Dwaraknath&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;shyamd@lbl.gov&quot;</span>
<span class="n">__status__</span> <span class="o">=</span> <span class="s2">&quot;Development&quot;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s2">&quot;Mar 15, 2018&quot;</span>

<span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>


<div class="viewcode-block" id="Defect"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.Defect">[docs]</a><span class="k">class</span> <span class="nc">Defect</span><span class="p">(</span><span class="n">MSONable</span><span class="p">,</span> <span class="n">metaclass</span><span class="o">=</span><span class="n">ABCMeta</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Abstract class for a single point defect</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">defect_site</span><span class="p">,</span> <span class="n">charge</span><span class="o">=</span><span class="mf">0.</span><span class="p">,</span> <span class="n">multiplicity</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initializes an abstract defect</span>

<span class="sd">        Args:</span>
<span class="sd">            structure: Pymatgen Structure without any defects</span>
<span class="sd">            defect_site (Site): site for defect within structure</span>
<span class="sd">                must have same lattice as structure</span>
<span class="sd">            charge: (int or float) defect charge</span>
<span class="sd">                default is zero, meaning no change to NELECT after defect is created in the structure</span>
<span class="sd">                (assuming use_structure_charge=True in vasp input set)</span>
<span class="sd">            multiplicity (int): multiplicity of defect within</span>
<span class="sd">                the supercell can be supplied by user. if not</span>
<span class="sd">                specified, then space group symmetry analysis is</span>
<span class="sd">                used to generate multiplicity.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_structure</span> <span class="o">=</span> <span class="n">structure</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_charge</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">charge</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_defect_site</span> <span class="o">=</span> <span class="n">defect_site</span>
        <span class="n">lattice_match</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">structure</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">matrix</span><span class="p">,</span>
                                    <span class="n">defect_site</span><span class="o">.</span><span class="n">lattice</span><span class="o">.</span><span class="n">matrix</span><span class="p">,</span>
                                    <span class="n">atol</span><span class="o">=</span><span class="mf">1e-5</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">lattice_match</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;defect_site lattice must be same as structure &quot;</span>
                             <span class="s2">&quot;lattice.&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_multiplicity</span> <span class="o">=</span> <span class="n">multiplicity</span> <span class="k">if</span> <span class="n">multiplicity</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_multiplicity</span><span class="p">()</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">bulk_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the structure without any defects.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_structure</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">charge</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the charge of a defect</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_charge</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">site</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the defect position as a site object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_defect_site</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">multiplicity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the multiplicity of a defect site within the structure (needed for concentration analysis)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_multiplicity</span>

    <span class="nd">@property</span>  <span class="c1"># type: ignore</span>
    <span class="nd">@abstractmethod</span>
    <span class="k">def</span> <span class="nf">defect_composition</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the defect composition as a Composition object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span>

<div class="viewcode-block" id="Defect.generate_defect_structure"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.Defect.generate_defect_structure">[docs]</a>    <span class="nd">@abstractmethod</span>
    <span class="k">def</span> <span class="nf">generate_defect_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">supercell</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Given structure and defect_site (and type of defect) should return a defect_structure that is charged</span>
<span class="sd">        Args:</span>
<span class="sd">            supercell (int, [3x1], or [[]] (3x3)): supercell integer, vector, or scaling matrix</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span></div>

    <span class="nd">@property</span>  <span class="c1"># type: ignore</span>
    <span class="nd">@abstractmethod</span>
    <span class="k">def</span> <span class="nf">name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a name for this defect</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span>

<div class="viewcode-block" id="Defect.get_multiplicity"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.Defect.get_multiplicity">[docs]</a>    <span class="nd">@abstractmethod</span>
    <span class="k">def</span> <span class="nf">get_multiplicity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Method to determine multiplicity. For non-Interstitial objects, also confirms that defect_site</span>
<span class="sd">        is a site in bulk_structure.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span></div>

<div class="viewcode-block" id="Defect.copy"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.Defect.copy">[docs]</a>    <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Convenience method to get a copy of the defect.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A copy of the Defect.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">as_dict</span><span class="p">())</span></div>

<div class="viewcode-block" id="Defect.set_charge"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.Defect.set_charge">[docs]</a>    <span class="k">def</span> <span class="nf">set_charge</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">new_charge</span><span class="o">=</span><span class="mf">0.</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Sets the overall charge</span>
<span class="sd">        Args:</span>
<span class="sd">            charge (float): new charge to set</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_charge</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">new_charge</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="Vacancy"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.Vacancy">[docs]</a><span class="k">class</span> <span class="nc">Vacancy</span><span class="p">(</span><span class="n">Defect</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Subclass of Defect to capture essential information for a single Vacancy defect structure.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">defect_composition</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns: Composition of defect.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">temp_comp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
        <span class="n">temp_comp</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="p">)]</span> <span class="o">-=</span> <span class="mi">1</span>
        <span class="k">return</span> <span class="n">Composition</span><span class="p">(</span><span class="n">temp_comp</span><span class="p">)</span>

<div class="viewcode-block" id="Vacancy.generate_defect_structure"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.Vacancy.generate_defect_structure">[docs]</a>    <span class="k">def</span> <span class="nf">generate_defect_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">supercell</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns Defective Vacancy structure, decorated with charge</span>
<span class="sd">        Args:</span>
<span class="sd">            supercell (int, [3x1], or [[]] (3x3)): supercell integer, vector, or scaling matrix</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">defect_structure</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">defect_structure</span><span class="o">.</span><span class="n">make_supercell</span><span class="p">(</span><span class="n">supercell</span><span class="p">)</span>

        <span class="c1"># create a trivial defect structure to find where supercell transformation moves the lattice</span>
        <span class="n">struct_for_defect_site</span> <span class="o">=</span> <span class="n">Structure</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span><span class="o">.</span><span class="n">lattice</span><span class="p">,</span>
                                           <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="p">],</span>
                                           <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">],</span>
                                           <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="n">struct_for_defect_site</span><span class="o">.</span><span class="n">make_supercell</span><span class="p">(</span><span class="n">supercell</span><span class="p">)</span>
        <span class="n">defect_site</span> <span class="o">=</span> <span class="n">struct_for_defect_site</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="n">poss_deflist</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span>
            <span class="n">defect_structure</span><span class="o">.</span><span class="n">get_sites_in_sphere</span><span class="p">(</span><span class="n">defect_site</span><span class="o">.</span><span class="n">coords</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="n">include_index</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="n">defindex</span> <span class="o">=</span> <span class="n">poss_deflist</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span>
        <span class="n">defect_structure</span><span class="o">.</span><span class="n">remove_sites</span><span class="p">([</span><span class="n">defindex</span><span class="p">])</span>
        <span class="n">defect_structure</span><span class="o">.</span><span class="n">set_charge</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">charge</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">defect_structure</span></div>

<div class="viewcode-block" id="Vacancy.get_multiplicity"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.Vacancy.get_multiplicity">[docs]</a>    <span class="k">def</span> <span class="nf">get_multiplicity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the multiplicity of a defect site within the structure (needed for concentration analysis)</span>
<span class="sd">        and confirms that defect_site is a site in bulk_structure.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">sga</span> <span class="o">=</span> <span class="n">SpacegroupAnalyzer</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="p">)</span>
        <span class="n">periodic_struc</span> <span class="o">=</span> <span class="n">sga</span><span class="o">.</span><span class="n">get_symmetrized_structure</span><span class="p">()</span>
        <span class="n">poss_deflist</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span>
            <span class="n">periodic_struc</span><span class="o">.</span><span class="n">get_sites_in_sphere</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">coords</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="n">include_index</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">len</span><span class="p">(</span><span class="n">poss_deflist</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Site </span><span class="si">{}</span><span class="s2"> is not in bulk structure! Cannot create Vacancy object.&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">defindex</span> <span class="o">=</span> <span class="n">poss_deflist</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span>
            <span class="n">defect_site</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="p">[</span><span class="n">defindex</span><span class="p">]</span>
            <span class="n">equivalent_sites</span> <span class="o">=</span> <span class="n">periodic_struc</span><span class="o">.</span><span class="n">find_equivalent_sites</span><span class="p">(</span><span class="n">defect_site</span><span class="p">)</span>
            <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="n">equivalent_sites</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a name for this defect</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="s2">&quot;Vac_</span><span class="si">{}</span><span class="s2">_mult</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">multiplicity</span><span class="p">)</span></div>


<div class="viewcode-block" id="Substitution"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.Substitution">[docs]</a><span class="k">class</span> <span class="nc">Substitution</span><span class="p">(</span><span class="n">Defect</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Subclass of Defect to capture essential information for a single Substitution defect structure.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="nd">@property</span>  <span class="c1"># type: ignore</span>
    <span class="nd">@lru_cache</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">defect_composition</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns: Composition of defect.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">poss_deflist</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="o">.</span><span class="n">get_sites_in_sphere</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">coords</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="n">include_index</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="n">defindex</span> <span class="o">=</span> <span class="n">poss_deflist</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span>

        <span class="n">temp_comp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
        <span class="n">temp_comp</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="p">)]</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="n">temp_comp</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="p">[</span><span class="n">defindex</span><span class="p">]</span><span class="o">.</span><span class="n">specie</span><span class="p">)]</span> <span class="o">-=</span> <span class="mi">1</span>
        <span class="k">return</span> <span class="n">Composition</span><span class="p">(</span><span class="n">temp_comp</span><span class="p">)</span>

<div class="viewcode-block" id="Substitution.generate_defect_structure"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.Substitution.generate_defect_structure">[docs]</a>    <span class="k">def</span> <span class="nf">generate_defect_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">supercell</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns Defective Substitution structure, decorated with charge.</span>
<span class="sd">        If bulk structure had any site properties, all of these properties are</span>
<span class="sd">        removed in the resulting defect structure.</span>

<span class="sd">        Args:</span>
<span class="sd">            supercell (int, [3x1], or [[]] (3x3)): supercell integer, vector, or scaling matrix</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">defect_structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span><span class="o">.</span><span class="n">lattice</span><span class="p">,</span>
                                     <span class="p">[</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="p">],</span>
                                     <span class="p">[</span><span class="n">site</span><span class="o">.</span><span class="n">frac_coords</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="p">],</span>
                                     <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                     <span class="n">site_properties</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>  <span class="c1"># remove all site_properties</span>
        <span class="n">defect_structure</span><span class="o">.</span><span class="n">make_supercell</span><span class="p">(</span><span class="n">supercell</span><span class="p">)</span>

        <span class="c1"># create a trivial defect structure to find where supercell transformation moves the defect</span>
        <span class="n">struct_for_defect_site</span> <span class="o">=</span> <span class="n">Structure</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span><span class="o">.</span><span class="n">lattice</span><span class="p">,</span>
                                           <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="p">],</span>
                                           <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">],</span>
                                           <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="n">struct_for_defect_site</span><span class="o">.</span><span class="n">make_supercell</span><span class="p">(</span><span class="n">supercell</span><span class="p">)</span>
        <span class="n">defect_site</span> <span class="o">=</span> <span class="n">struct_for_defect_site</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="n">poss_deflist</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span>
            <span class="n">defect_structure</span><span class="o">.</span><span class="n">get_sites_in_sphere</span><span class="p">(</span><span class="n">defect_site</span><span class="o">.</span><span class="n">coords</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="n">include_index</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="n">defindex</span> <span class="o">=</span> <span class="n">poss_deflist</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span>

        <span class="n">subsite</span> <span class="o">=</span> <span class="n">defect_structure</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">defindex</span><span class="p">)</span>
        <span class="n">defect_structure</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="o">.</span><span class="n">symbol</span><span class="p">,</span> <span class="n">subsite</span><span class="o">.</span><span class="n">coords</span><span class="p">,</span> <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                <span class="n">properties</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
        <span class="n">defect_structure</span><span class="o">.</span><span class="n">set_charge</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">charge</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">defect_structure</span></div>

<div class="viewcode-block" id="Substitution.get_multiplicity"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.Substitution.get_multiplicity">[docs]</a>    <span class="k">def</span> <span class="nf">get_multiplicity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the multiplicity of a defect site within the structure (needed for concentration analysis)</span>
<span class="sd">        and confirms that defect_site is a site in bulk_structure.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">sga</span> <span class="o">=</span> <span class="n">SpacegroupAnalyzer</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="p">)</span>
        <span class="n">periodic_struc</span> <span class="o">=</span> <span class="n">sga</span><span class="o">.</span><span class="n">get_symmetrized_structure</span><span class="p">()</span>
        <span class="n">poss_deflist</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span>
            <span class="n">periodic_struc</span><span class="o">.</span><span class="n">get_sites_in_sphere</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">coords</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="n">include_index</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">len</span><span class="p">(</span><span class="n">poss_deflist</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Site </span><span class="si">{}</span><span class="s2"> is not in bulk structure! Cannot create Substitution object.&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">defindex</span> <span class="o">=</span> <span class="n">poss_deflist</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span>
            <span class="n">defect_site</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="p">[</span><span class="n">defindex</span><span class="p">]</span>
            <span class="n">equivalent_sites</span> <span class="o">=</span> <span class="n">periodic_struc</span><span class="o">.</span><span class="n">find_equivalent_sites</span><span class="p">(</span><span class="n">defect_site</span><span class="p">)</span>
            <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="n">equivalent_sites</span><span class="p">)</span></div>

    <span class="nd">@property</span>  <span class="c1"># type: ignore</span>
    <span class="nd">@lru_cache</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a name for this defect</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">poss_deflist</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="o">.</span><span class="n">get_sites_in_sphere</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">coords</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="n">include_index</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="n">defindex</span> <span class="o">=</span> <span class="n">poss_deflist</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span>
        <span class="k">return</span> <span class="s2">&quot;Sub_</span><span class="si">{}</span><span class="s2">_on_</span><span class="si">{}</span><span class="s2">_mult</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="p">[</span><span class="n">defindex</span><span class="p">]</span><span class="o">.</span><span class="n">specie</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">multiplicity</span><span class="p">)</span></div>


<div class="viewcode-block" id="Interstitial"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.Interstitial">[docs]</a><span class="k">class</span> <span class="nc">Interstitial</span><span class="p">(</span><span class="n">Defect</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Subclass of Defect to capture essential information for a single Interstitial defect structure.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structure</span><span class="p">,</span> <span class="n">defect_site</span><span class="p">,</span> <span class="n">charge</span><span class="o">=</span><span class="mf">0.</span><span class="p">,</span> <span class="n">site_name</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">multiplicity</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initializes an interstial defect.</span>
<span class="sd">        Args:</span>
<span class="sd">            structure: Pymatgen Structure without any defects</span>
<span class="sd">            defect_site (Site): the site for the interstitial</span>
<span class="sd">            charge: (int or float) defect charge</span>
<span class="sd">                default is zero, meaning no change to NELECT after defect is created in the structure</span>
<span class="sd">                (assuming use_structure_charge=True in vasp input set)</span>
<span class="sd">            site_name: allows user to give a unique name to defect, since Wyckoff symbol/multiplicity</span>
<span class="sd">                is sometimes insufficient to categorize the defect type.</span>
<span class="sd">                default is no name beyond multiplicity.</span>
<span class="sd">            multiplicity (int): multiplicity of defect within</span>
<span class="sd">                the supercell can be supplied by user. if not</span>
<span class="sd">                specified, then space group symmetry is used</span>
<span class="sd">                to generator interstitial sublattice</span>

<span class="sd">                NOTE: multiplicity generation will not work for</span>
<span class="sd">                interstitial complexes,</span>
<span class="sd">                where multiplicity may depend on additional</span>
<span class="sd">                factors (ex. orientation etc.)</span>
<span class="sd">                If defect is not a complex, then this</span>
<span class="sd">                process will yield the correct multiplicity,</span>
<span class="sd">                provided that the defect does not undergo</span>
<span class="sd">                significant relaxation.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">structure</span><span class="o">=</span><span class="n">structure</span><span class="p">,</span> <span class="n">defect_site</span><span class="o">=</span><span class="n">defect_site</span><span class="p">,</span> <span class="n">charge</span><span class="o">=</span><span class="n">charge</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_multiplicity</span> <span class="o">=</span> <span class="n">multiplicity</span> <span class="k">if</span> <span class="n">multiplicity</span> <span class="k">else</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_multiplicity</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">site_name</span> <span class="o">=</span> <span class="n">site_name</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">defect_composition</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns: Defect composition.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">temp_comp</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
        <span class="n">temp_comp</span><span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="p">)]</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="k">return</span> <span class="n">Composition</span><span class="p">(</span><span class="n">temp_comp</span><span class="p">)</span>

<div class="viewcode-block" id="Interstitial.generate_defect_structure"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.Interstitial.generate_defect_structure">[docs]</a>    <span class="k">def</span> <span class="nf">generate_defect_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">supercell</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns Defective Interstitial structure, decorated with charge</span>
<span class="sd">        If bulk structure had any site properties, all of these properties are</span>
<span class="sd">        removed in the resulting defect structure</span>

<span class="sd">        Args:</span>
<span class="sd">            supercell (int, [3x1], or [[]] (3x3)): supercell integer, vector, or scaling matrix</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">defect_structure</span> <span class="o">=</span> <span class="n">Structure</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span><span class="o">.</span><span class="n">lattice</span><span class="p">,</span>
                                     <span class="p">[</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="p">],</span>
                                     <span class="p">[</span><span class="n">site</span><span class="o">.</span><span class="n">frac_coords</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="p">],</span>
                                     <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                                     <span class="n">site_properties</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>  <span class="c1"># remove all site_properties</span>
        <span class="n">defect_structure</span><span class="o">.</span><span class="n">make_supercell</span><span class="p">(</span><span class="n">supercell</span><span class="p">)</span>

        <span class="c1"># create a trivial defect structure to find where supercell transformation moves the defect site</span>
        <span class="n">struct_for_defect_site</span> <span class="o">=</span> <span class="n">Structure</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span><span class="o">.</span><span class="n">lattice</span><span class="p">,</span>
                                           <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="p">],</span>
                                           <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">frac_coords</span><span class="p">],</span>
                                           <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="n">struct_for_defect_site</span><span class="o">.</span><span class="n">make_supercell</span><span class="p">(</span><span class="n">supercell</span><span class="p">)</span>
        <span class="n">defect_site</span> <span class="o">=</span> <span class="n">struct_for_defect_site</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="n">defect_structure</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="o">.</span><span class="n">symbol</span><span class="p">,</span> <span class="n">defect_site</span><span class="o">.</span><span class="n">coords</span><span class="p">,</span> <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                <span class="n">properties</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
        <span class="n">defect_structure</span><span class="o">.</span><span class="n">set_charge</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">charge</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">defect_structure</span></div>

<div class="viewcode-block" id="Interstitial.get_multiplicity"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.Interstitial.get_multiplicity">[docs]</a>    <span class="k">def</span> <span class="nf">get_multiplicity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the multiplicity of a defect site within the structure (needed for concentration analysis)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">d_structure</span> <span class="o">=</span> <span class="n">create_saturated_interstitial_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;WARNING! Multiplicity was not able to be calculated adequately &#39;</span>
                         <span class="s1">&#39;for interstitials...setting this to 1 and skipping for now...&#39;</span><span class="p">)</span>
            <span class="k">return</span> <span class="mi">1</span>

        <span class="n">sga</span> <span class="o">=</span> <span class="n">SpacegroupAnalyzer</span><span class="p">(</span><span class="n">d_structure</span><span class="p">)</span>
        <span class="n">periodic_struc</span> <span class="o">=</span> <span class="n">sga</span><span class="o">.</span><span class="n">get_symmetrized_structure</span><span class="p">()</span>
        <span class="n">poss_deflist</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span>
            <span class="n">periodic_struc</span><span class="o">.</span><span class="n">get_sites_in_sphere</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">coords</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">,</span> <span class="n">include_index</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span>
            <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
        <span class="n">defindex</span> <span class="o">=</span> <span class="n">poss_deflist</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span>

        <span class="n">equivalent_sites</span> <span class="o">=</span> <span class="n">periodic_struc</span><span class="o">.</span><span class="n">find_equivalent_sites</span><span class="p">(</span><span class="n">periodic_struc</span><span class="p">[</span><span class="n">defindex</span><span class="p">])</span>
        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="n">equivalent_sites</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a name for this defect</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">site_name</span><span class="p">:</span>
            <span class="k">return</span> <span class="s2">&quot;Int_</span><span class="si">{}</span><span class="s2">_</span><span class="si">{}</span><span class="s2">_mult</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">site_name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">multiplicity</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="s2">&quot;Int_</span><span class="si">{}</span><span class="s2">_mult</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">multiplicity</span><span class="p">)</span></div>


<div class="viewcode-block" id="create_saturated_interstitial_structure"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.create_saturated_interstitial_structure">[docs]</a><span class="k">def</span> <span class="nf">create_saturated_interstitial_structure</span><span class="p">(</span><span class="n">interstitial_def</span><span class="p">,</span> <span class="n">dist_tol</span><span class="o">=</span><span class="mf">0.1</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    this takes a Interstitial defect object and generates the</span>
<span class="sd">    sublattice for it based on the structure&#39;s space group.</span>
<span class="sd">    Useful for understanding multiplicity of an interstitial</span>
<span class="sd">    defect in thermodynamic analysis.</span>

<span class="sd">    NOTE: if large relaxation happens to interstitial or</span>
<span class="sd">        defect involves a complex then there may be additional</span>
<span class="sd">        degrees of freedom that need to be considered for</span>
<span class="sd">        the multiplicity.</span>

<span class="sd">    Args:</span>
<span class="sd">        dist_tol: changing distance tolerance of saturated structure,</span>
<span class="sd">                allowing for possibly overlapping sites</span>
<span class="sd">                but ensuring space group is maintained</span>

<span class="sd">    Returns:</span>
<span class="sd">        Structure object decorated with interstitial site equivalents</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">sga</span> <span class="o">=</span> <span class="n">SpacegroupAnalyzer</span><span class="p">(</span><span class="n">interstitial_def</span><span class="o">.</span><span class="n">bulk_structure</span><span class="o">.</span><span class="n">copy</span><span class="p">())</span>
    <span class="n">sg_ops</span> <span class="o">=</span> <span class="n">sga</span><span class="o">.</span><span class="n">get_symmetry_operations</span><span class="p">(</span><span class="n">cartesian</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

    <span class="c1"># copy bulk structure to make saturated interstitial structure out of</span>
    <span class="c1"># artificially lower distance_tolerance to allow for distinct interstitials</span>
    <span class="c1"># with lower symmetry to be replicated - This is OK because one would never</span>
    <span class="c1"># actually use this structure for a practical calcualtion...</span>
    <span class="n">saturated_defect_struct</span> <span class="o">=</span> <span class="n">interstitial_def</span><span class="o">.</span><span class="n">bulk_structure</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
    <span class="n">saturated_defect_struct</span><span class="o">.</span><span class="n">DISTANCE_TOLERANCE</span> <span class="o">=</span> <span class="n">dist_tol</span>

    <span class="k">for</span> <span class="n">sgo</span> <span class="ow">in</span> <span class="n">sg_ops</span><span class="p">:</span>
        <span class="n">new_interstit_coords</span> <span class="o">=</span> <span class="n">sgo</span><span class="o">.</span><span class="n">operate</span><span class="p">(</span><span class="n">interstitial_def</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">coords</span><span class="p">[:])</span>
        <span class="n">poss_new_site</span> <span class="o">=</span> <span class="n">PeriodicSite</span><span class="p">(</span>
            <span class="n">interstitial_def</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">specie</span><span class="p">,</span>
            <span class="n">new_interstit_coords</span><span class="p">,</span>
            <span class="n">saturated_defect_struct</span><span class="o">.</span><span class="n">lattice</span><span class="p">,</span>
            <span class="n">to_unit_cell</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
            <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="c1"># will raise value error if site already exists in structure</span>
            <span class="n">saturated_defect_struct</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="n">poss_new_site</span><span class="o">.</span><span class="n">specie</span><span class="p">,</span> <span class="n">poss_new_site</span><span class="o">.</span><span class="n">coords</span><span class="p">,</span>
                <span class="n">coords_are_cartesian</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">validate_proximity</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
            <span class="k">pass</span>

    <span class="c1"># do final space group analysis to make sure symmetry not lowered by saturating defect structure</span>
    <span class="n">saturated_sga</span> <span class="o">=</span> <span class="n">SpacegroupAnalyzer</span><span class="p">(</span><span class="n">saturated_defect_struct</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">saturated_sga</span><span class="o">.</span><span class="n">get_space_group_number</span><span class="p">()</span> <span class="o">!=</span> <span class="n">sga</span><span class="o">.</span><span class="n">get_space_group_number</span><span class="p">():</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Warning! Interstitial sublattice generation &quot;</span>
                         <span class="s2">&quot;has changed space group symmetry. Recommend &quot;</span>
                         <span class="s2">&quot;reducing dist_tol and trying again...&quot;</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">saturated_defect_struct</span></div>


<div class="viewcode-block" id="DefectEntry"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.DefectEntry">[docs]</a><span class="k">class</span> <span class="nc">DefectEntry</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    An lightweight DefectEntry object containing key computed data</span>
<span class="sd">    for many defect analysis.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">defect</span><span class="p">,</span> <span class="n">uncorrected_energy</span><span class="p">,</span> <span class="n">corrections</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">parameters</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">entry_id</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            defect:</span>
<span class="sd">                A Defect object from pymatgen.analysis.defects.core</span>
<span class="sd">            uncorrected_energy (float): Energy of the defect entry. Usually the difference between</span>
<span class="sd">                the final calculated energy for the defect supercell - the perfect</span>
<span class="sd">                supercell energy</span>
<span class="sd">            corrections (dict):</span>
<span class="sd">                Dict of corrections for defect formation energy. All values will be summed and</span>
<span class="sd">                added to the defect formation energy.</span>
<span class="sd">            parameters (dict): An optional dict of calculation parameters and data to</span>
<span class="sd">                use with correction schemes</span>
<span class="sd">                (examples of parameter keys: supercell_size, axis_grid, bulk_planar_averages</span>
<span class="sd">                defect_planar_averages )</span>
<span class="sd">            entry_id (obj): An id to uniquely identify this defect, can be any MSONable</span>
<span class="sd">                type</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">defect</span> <span class="o">=</span> <span class="n">defect</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">uncorrected_energy</span> <span class="o">=</span> <span class="n">uncorrected_energy</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">corrections</span> <span class="o">=</span> <span class="n">corrections</span> <span class="k">if</span> <span class="n">corrections</span> <span class="k">else</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">entry_id</span> <span class="o">=</span> <span class="n">entry_id</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span> <span class="o">=</span> <span class="n">parameters</span> <span class="k">if</span> <span class="n">parameters</span> <span class="k">else</span> <span class="p">{}</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">bulk_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns: Structure object of bulk.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">defect</span><span class="o">.</span><span class="n">bulk_structure</span>

<div class="viewcode-block" id="DefectEntry.as_dict"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.DefectEntry.as_dict">[docs]</a>    <span class="k">def</span> <span class="nf">as_dict</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Json-serializable dict representation of DefectEntry</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">d</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;@module&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__module__</span><span class="p">,</span>
             <span class="s2">&quot;@class&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span>
             <span class="s2">&quot;defect&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">defect</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span>
             <span class="s2">&quot;uncorrected_energy&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">uncorrected_energy</span><span class="p">,</span>
             <span class="s2">&quot;corrections&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">corrections</span><span class="p">,</span>
             <span class="s2">&quot;parameters&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="p">,</span>
             <span class="s2">&quot;entry_id&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">entry_id</span><span class="p">}</span>
        <span class="k">return</span> <span class="n">d</span></div>

<div class="viewcode-block" id="DefectEntry.from_dict"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.DefectEntry.from_dict">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">from_dict</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">d</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Reconstitute a DefectEntry object from a dict representation created using</span>
<span class="sd">        as_dict().</span>
<span class="sd">         Args:</span>
<span class="sd">            d (dict): dict representation of DefectEntry.</span>
<span class="sd">         Returns:</span>
<span class="sd">            DefectEntry object</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">defect</span> <span class="o">=</span> <span class="n">MontyDecoder</span><span class="p">()</span><span class="o">.</span><span class="n">process_decoded</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;defect&quot;</span><span class="p">])</span>
        <span class="n">uncorrected_energy</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;uncorrected_energy&quot;</span><span class="p">]</span>
        <span class="n">corrections</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;corrections&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">parameters</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;parameters&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="n">entry_id</span> <span class="o">=</span> <span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;entry_id&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="n">defect</span><span class="p">,</span> <span class="n">uncorrected_energy</span><span class="p">,</span> <span class="n">corrections</span><span class="o">=</span><span class="n">corrections</span><span class="p">,</span>
                   <span class="n">parameters</span><span class="o">=</span><span class="n">parameters</span><span class="p">,</span> <span class="n">entry_id</span><span class="o">=</span><span class="n">entry_id</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">site</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns: Site of defect.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">defect</span><span class="o">.</span><span class="n">site</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">multiplicity</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns: Multiplicity of defect.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">defect</span><span class="o">.</span><span class="n">multiplicity</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">charge</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns: Charge of defect.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">defect</span><span class="o">.</span><span class="n">charge</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">energy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns: *Corrected* energy of the entry</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">uncorrected_energy</span> <span class="o">+</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">corrections</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns: Defect name</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">defect</span><span class="o">.</span><span class="n">name</span>

<div class="viewcode-block" id="DefectEntry.copy"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.DefectEntry.copy">[docs]</a>    <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Convenience method to get a copy of the DefectEntry.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A copy of the DefectEntry.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">defectentry_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">DefectEntry</span><span class="o">.</span><span class="n">from_dict</span><span class="p">(</span><span class="n">defectentry_dict</span><span class="p">)</span></div>

<div class="viewcode-block" id="DefectEntry.formation_energy"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.DefectEntry.formation_energy">[docs]</a>    <span class="k">def</span> <span class="nf">formation_energy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">chemical_potentials</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">fermi_level</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Compute the formation energy for a defect taking into account a given chemical potential and fermi_level</span>
<span class="sd">         Args:</span>
<span class="sd">             chemical_potentials (dict): Dictionary of elemental chemical potential values.</span>
<span class="sd">                Keys are Element objects within the defect structure&#39;s composition.</span>
<span class="sd">                Values are float numbers equal to the atomic chemical potential for that element.</span>
<span class="sd">            fermi_level (float):  Value corresponding to the electron chemical potential.</span>
<span class="sd">                If &quot;vbm&quot; is supplied in parameters dict, then fermi_level is referenced to the VBM.</span>
<span class="sd">                If &quot;vbm&quot; is NOT supplied in parameters dict, then fermi_level is referenced to the</span>
<span class="sd">                calculation&#39;s absolute Kohn-Sham potential (and should include the vbm value provided</span>
<span class="sd">                by a band structure calculation)</span>

<span class="sd">        Returns:</span>
<span class="sd">            Formation energy value (float)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">chemical_potentials</span> <span class="o">=</span> <span class="n">chemical_potentials</span> <span class="k">if</span> <span class="n">chemical_potentials</span> <span class="k">else</span> <span class="p">{}</span>

        <span class="n">chempot_correction</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">([</span>
            <span class="n">chem_pot</span> <span class="o">*</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bulk_structure</span><span class="o">.</span><span class="n">composition</span><span class="p">[</span><span class="n">el</span><span class="p">]</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">defect</span><span class="o">.</span><span class="n">defect_composition</span><span class="p">[</span><span class="n">el</span><span class="p">])</span>
            <span class="k">for</span> <span class="n">el</span><span class="p">,</span> <span class="n">chem_pot</span> <span class="ow">in</span> <span class="n">chemical_potentials</span><span class="o">.</span><span class="n">items</span><span class="p">()</span>
        <span class="p">])</span>

        <span class="n">formation_energy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">energy</span> <span class="o">+</span> <span class="n">chempot_correction</span>

        <span class="k">if</span> <span class="s2">&quot;vbm&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="p">:</span>
            <span class="n">formation_energy</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">charge</span> <span class="o">*</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="p">[</span><span class="s2">&quot;vbm&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">fermi_level</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">formation_energy</span> <span class="o">+=</span> <span class="bp">self</span><span class="o">.</span><span class="n">charge</span> <span class="o">*</span> <span class="n">fermi_level</span>

        <span class="k">return</span> <span class="n">formation_energy</span></div>

<div class="viewcode-block" id="DefectEntry.defect_concentration"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.DefectEntry.defect_concentration">[docs]</a>    <span class="k">def</span> <span class="nf">defect_concentration</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">chemical_potentials</span><span class="p">,</span> <span class="n">temperature</span><span class="o">=</span><span class="mi">300</span><span class="p">,</span> <span class="n">fermi_level</span><span class="o">=</span><span class="mf">0.0</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Compute the defect concentration for a temperature and Fermi level.</span>
<span class="sd">        Args:</span>
<span class="sd">            temperature:</span>
<span class="sd">                the temperature in K</span>
<span class="sd">            fermi_level:</span>
<span class="sd">                the fermi level in eV (with respect to the VBM)</span>
<span class="sd">        Returns:</span>
<span class="sd">            defects concentration in cm^-3</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">n</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">multiplicity</span> <span class="o">*</span> <span class="mf">1e24</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">defect</span><span class="o">.</span><span class="n">bulk_structure</span><span class="o">.</span><span class="n">volume</span>
        <span class="n">conc</span> <span class="o">=</span> <span class="n">n</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="mf">1.0</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">formation_energy</span><span class="p">(</span><span class="n">chemical_potentials</span><span class="p">,</span> <span class="n">fermi_level</span><span class="o">=</span><span class="n">fermi_level</span><span class="p">)</span> <span class="o">/</span>
                          <span class="p">(</span><span class="n">kb</span> <span class="o">*</span> <span class="n">temperature</span><span class="p">))</span>

        <span class="k">return</span> <span class="n">conc</span></div>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Human readable string representation of this entry</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">output</span> <span class="o">=</span> <span class="p">[</span>
            <span class="s2">&quot;DefectEntry </span><span class="si">{}</span><span class="s2"> - </span><span class="si">{}</span><span class="s2"> - charge </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">entry_id</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">charge</span><span class="p">),</span>
            <span class="s2">&quot;Energy = </span><span class="si">{:.4f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">energy</span><span class="p">),</span>
            <span class="s2">&quot;Correction = </span><span class="si">{:.4f}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">corrections</span><span class="o">.</span><span class="n">values</span><span class="p">()))),</span>
            <span class="s2">&quot;Parameters:&quot;</span>
        <span class="p">]</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parameters</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">output</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\t</span><span class="si">{}</span><span class="s2"> = </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">))</span>
        <span class="k">return</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">output</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="fm">__repr__</span><span class="p">()</span></div>


<div class="viewcode-block" id="DefectCorrection"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.DefectCorrection">[docs]</a><span class="k">class</span> <span class="nc">DefectCorrection</span><span class="p">(</span><span class="n">MSONable</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A Correction class modeled off the computed entry correction format</span>
<span class="sd">    &quot;&quot;&quot;</span>

<div class="viewcode-block" id="DefectCorrection.get_correction"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.DefectCorrection.get_correction">[docs]</a>    <span class="nd">@abstractmethod</span>
    <span class="k">def</span> <span class="nf">get_correction</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">entry</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns correction for a single entry.</span>

<span class="sd">        Args:</span>
<span class="sd">            entry: A DefectEntry object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A single dictionary with the format</span>
<span class="sd">            correction_name: energy_correction</span>

<span class="sd">        Raises:</span>
<span class="sd">            CompatibilityError if entry is not compatible.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span></div>

<div class="viewcode-block" id="DefectCorrection.correct_entry"><a class="viewcode-back" href="../../../../pymatgen.analysis.defects.core.html#pymatgen.analysis.defects.core.DefectCorrection.correct_entry">[docs]</a>    <span class="k">def</span> <span class="nf">correct_entry</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">entry</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Corrects a single entry.</span>

<span class="sd">        Args:</span>
<span class="sd">            entry: A DefectEntry object.</span>

<span class="sd">        Returns:</span>
<span class="sd">            An processed entry.</span>

<span class="sd">        Raises:</span>
<span class="sd">            CompatibilityError if entry is not compatible.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">entry</span><span class="o">.</span><span class="n">correction</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_correction</span><span class="p">(</span><span class="n">entry</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">entry</span></div></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.defects.core</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>